package com.ht.system.controller;


import com.ht.common.core.utils.SnowflakeIdWorker;
import com.ht.common.core.utils.StringUtils;
import com.ht.common.core.web.controller.BaseController;
import com.ht.common.core.web.domain.AjaxResult;
import com.ht.common.core.web.page.TableDataInfo;
import com.ht.common.log.annotation.Log;
import com.ht.common.log.enums.BusinessType;
import com.ht.common.security.annotation.RequiresPermissions;
import com.ht.common.security.utils.SecurityUtils;
import com.ht.system.domain.SysPlatform;
import com.ht.system.service.ISysPlatformService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 系统平台管理Controller
 *
 * @author ruoyi
 * @date 2023-06-29
 */
@Api(tags = "系统平台管理")
@RestController
@RequestMapping("/platform")
public class SysPlatformController extends BaseController {

    @Autowired
    private ISysPlatformService sysPlatformService;

    /**
     * 查询系统平台管理列表
     */
    @GetMapping("/list")
    @ApiOperation("查询系统平台管理列表")
    public TableDataInfo list(SysPlatform sysPlatform) {
        startPage();
        List<SysPlatform> list = sysPlatformService.selectSysPlatformList(sysPlatform);
        return getDataTable(list);
    }

    @GetMapping("/getList")
    public AjaxResult getList(){
        List<SysPlatform> list = sysPlatformService.selectSysPlatformList(new SysPlatform());
        return AjaxResult.success(list);
    }



    /**
     * 获取系统平台管理详细信息
     */
    @RequiresPermissions("system:platform:query")
    @GetMapping(value = "/getInfo/{platformId}")
    @ApiOperation("获取系统平台管理详细信息")
    public AjaxResult getInfo(@PathVariable("platformId") String platformId) {
        return AjaxResult.success(sysPlatformService.selectSysPlatformByPlatformId(platformId));
    }

    /**
     * 新增系统平台管理
     */
    @RequiresPermissions("system:platform:add")
    @Log(title = "系统平台管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增系统平台管理")
    public AjaxResult add(@RequestBody SysPlatform sysPlatform) {
        sysPlatform.setPlatformId(sysPlatform.getPlatformSource());
        sysPlatform.setCreateBy(SecurityUtils.getNickName());
        sysPlatform.setCreateTime(new Date());
        return toAjax(sysPlatformService.insertSysPlatform(sysPlatform));
    }

    /**
     * 修改系统平台管理
     */
    @RequiresPermissions("system:platform:edit")
    @Log(title = "系统平台管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ApiOperation("修改系统平台管理")
    public AjaxResult edit(@RequestBody SysPlatform sysPlatform) {
        sysPlatform.setUpdateBy(SecurityUtils.getNickName());
        sysPlatform.setUpdateTime(new Date());
        return toAjax(sysPlatformService.updateSysPlatform(sysPlatform));
    }

    /**
     * 删除系统平台管理
     */
    @RequiresPermissions("system:platform:remove")
    @Log(title = "系统平台管理", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{platformIds}")
    @ApiOperation("删除系统平台管理")
    public AjaxResult remove(@PathVariable @ApiParam("id数组") String[] platformIds) {
        return toAjax(sysPlatformService.deleteSysPlatformByPlatformIds(platformIds));
    }
}
